﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XrmLibrary.MsCrm4Adapter.Extensions
{
    public static class ResourceInfoExtensions
    {
        public static Microsoft.Crm.Sdk.Messages.ResourceInfo ToCrm2011ResourceInfo(this Microsoft.Crm.Sdk.ResourceInfo crm4ResourceInfo)
        {
            Microsoft.Crm.Sdk.Messages.ResourceInfo crm2011ResourceInfo =
                new Microsoft.Crm.Sdk.Messages.ResourceInfo
                {
                    DisplayName = crm4ResourceInfo.DisplayName,
                    EntityName = crm4ResourceInfo.EntityName,
                    Id = crm4ResourceInfo.Id
                };

            return crm2011ResourceInfo;
        }

        public static IEnumerable<Microsoft.Crm.Sdk.Messages.ResourceInfo> ToCrm2011ResourceInfoCollection(this Microsoft.Crm.Sdk.ResourceInfo[] crm4ResourceInfo)
        {
            foreach (Microsoft.Crm.Sdk.ResourceInfo resourceInfo in crm4ResourceInfo)
            {
                yield return resourceInfo.ToCrm2011ResourceInfo();
            }
        }
    }
}
